package main

import (
	"encoding/xml"
	"fmt"
	"strings"
)

/*
<xml>
	<ToUserName><![CDATA[toUser]]></ToUserName>
	<FromUserName><![CDATA[fromUser]]></FromUserName>
	<CreateTime>1348831860</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[this is a test]]></Content>
	<MsgId>1234567890123456</MsgId>
</xml>
*/

type TextMessage struct {
	ToUserName   string
	FromUserName string
	CreateTime   int64
	MsgType      string
	Content      string
	MsgId        string
}

func main() {
	input := `<xml>
	<ToUserName><![CDATA[toUser]]></ToUserName>
	<FromUserName><![CDATA[fromUser]]></FromUserName>
	<CreateTime>1348831860</CreateTime>
	<MsgType><![CDATA[text]]></MsgType>
	<Content><![CDATA[this is a test]]></Content>
	<MsgId>1234567890123456</MsgId>
</xml>`
	inputReader := strings.NewReader(input)
	decoder := xml.NewDecoder(inputReader)

	textMessage := new(TextMessage)
	decoder.Decode(textMessage)

	fmt.Println(textMessage.Content)
	fmt.Printf("%+v\n", textMessage)


	bs,err:=xml.Marshal(*textMessage)
	if err!=nil{
		fmt.Println("xx")
	}
	fmt.Println(string(bs))
}
